package com.wfh.rpc.proxy;

import java.lang.reflect.Proxy;

/**
 * @Title: ServiceProxyFactory
 * @Author wangfenghuan
 * @Package com.wfh.rpc.proxy
 * @Date 2025/10/12 13:53
 * @description: 动态代理工厂类
 */
public class ServiceProxyFactory {

    /**
     * 根据服务类型获取代理对象
     * @param serviceClass
     * @return
     * @param <T>
     */
    public static <T> T getProxy(Class<T> serviceClass){
        return (T) Proxy.newProxyInstance(
                serviceClass.getClassLoader(),
                new Class[]{serviceClass},
                new ServiceProxy()
        );
    }

    /**
     * 根据服务类获取mock代理对象
     * @param serviceClass
     * @return
     * @param <T>
     */
    public static <T> T getMethodProxy(Class<T> serviceClass){
        return (T) Proxy.newProxyInstance(
                serviceClass.getClassLoader(),
                new Class[]{serviceClass},
                new MockServiceProxy()
        );
    }

}
